package cn.tedu.pojo;

import cn.tedu.dao.EmpMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MybatisDemo05 {
    SqlSession session = null;

    /*@Before标记会在每个@Test标记的方法之前执行！*/
    @Before
    public void beforeMethod() throws Exception {
        InputStream in = Resources.getResourceAsStream("mybatis-config.xml");

        SqlSessionFactory fac = new SqlSessionFactoryBuilder().build(in);
        //添加true会自动提交事务，默认是false，表示关闭提交
        session = fac.openSession(true);
        }
        /*测试mybatis的Mapper接口开发*/
    @Test
    public void testFindAll(){
         EmpMapper mapper=session.getMapper(EmpMapper.class);
         List <Emp>list=mapper.findAll();
         for(Emp emp : list){
             System.out.println(emp);
         }
    }
    }
